<template>
  <div class="right-home">
    <template v-if="isShow==='1'">
      <div class="right-home-top">
        <div class="sele">
          <el-select v-model="value" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="btn">
          <el-button @click="added" type="primary">新建</el-button>
        </div>
      </div>
      <div class="right-home-foot">
        <div
          class="attribute-box"
          v-for="(item, index) in formData"
          :key="index"
          @dblclick="shishiClick(index)"
        >
          <div>
            <div class="text">{{ item.name }}</div>
            <div @click="open(index)" class="switch">
              <i class="el-icon-delete"></i>
              <div :class="item.slide === true ? 'slide' : 'close-slide'"></div>
            </div>
          </div>
        </div>
      </div>
    </template>
    <template  >
        <RightCameraDetails/>
    </template>
  </div>
</template>

<script lang="ts">
import { Component, Vue ,Watch} from "vue-property-decorator";
import { ParameterManagementModule } from "@/store/modules/ParameterManagement";
import RightCameraDetails from './RightCameraDetails.vue'
@Component({
  components:{RightCameraDetails}
})
export default class RightCameraHome extends Vue {
  // public isShow=''
  public options: object = [
    {
      value: "选项1",
      label: "黄金糕",
    },
    {
      value: "选项2",
      label: "双皮奶",
    },
  ];
  public value: string = "";
  //开关按钮
  public slide: boolean = false;

  public input: string | number = "";
  public Inputbox: boolean = false;
  public formData: Array<any> = [
    { name: "主控室10", slide: false },
    { name: "主控室1", slide: false },
    { name: "主控室2", slide: false },
    { name: "主控室3", slide: false },
    { name: "主控室4", slide: false },
    { name: "主控室5", slide: false },
    { name: "主控室6", slide: false },
  ];
  get isShow(){
    return ParameterManagementModule.TreeId 
  }
  //删除按钮提示框
  open(index: number) {
    var _this = this;
    this.formData[index].slide = true;
    this.$confirm("此操作将永久删除该文件, 是否继续?", "删除", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        this.$message({
          type: "success",
          message: "删除成功!",
        });
        this.formData.splice(index, 1);
      })
      .catch(() => {
        _this.formData[index].slide = false;
        this.$message({
          type: "info",
          message: "已取消删除",
        });
      });
  }
  //新增
  added(){
    this.$prompt("请输入维护区域名称", "新增", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      // inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
      inputErrorMessage: "维护区域名称格式不正确",
    })
      .then((value) => {
        this.formData.push({ name: (value as any).value, slide: false },)
        this.$message({
          type: "success",
          message: "维护区域名称是: " + (value as any).value,
        });
      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "取消输入",
        });
      });
  }
  shishiClick(index: number) {
    this.formData[index].Inputbox = true;

    this.$prompt("请输入维护区域名称", "修改", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      // inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
      inputErrorMessage: "维护区域名称格式不正确",
    })
      .then((value) => {
        this.formData[index].name = (value as any).value;
        this.$message({
          type: "success",
          message: "维护区域名称是: " + (value as any).value,
        });
      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "取消输入",
        });
      });
  }
}
</script>

<style lang="scss" scoped>
.right-home {
  width: 100%;
  height: 100%;
  .right-home-top {
    width: 100%;
    height: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    .sele {
      margin-right: 0.3rem;
    }
    .btn {
      margin-right: 0.4rem;
      .el-button--primary {
        font-size: 0.18rem;
      }
    }
  }
  .right-home-foot {
    width: 100%;
    height: calc(100% - 0.9rem);
    overflow: auto;
    box-sizing: border-box;
    .attribute-box {
      width: 3rem;
      height: 1.79rem;
      display: inline-block;
      margin: 0.2rem 0.31rem;
      background: url(../../../../../../assets/img/ParameterManagement/men.png);
      background-size: 100% 100%;
      box-shadow: 0px 0.05rem 0.1rem #08153f;
      position: relative;
      > div {
        width: 52%;
        height: 70%;
        position: absolute;
        top: 50%;
        right: 0.02rem;
        transform: translateY(-50%);
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .text {
          font-size: 0.24rem;
          width: 100%;
          cursor: pointer;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .switch {
          display: inline-block;
          width: 80px;
          height: 26px;
          border-radius: 13px;
          border: 1px solid rgba(171, 179, 200, 0.5);
          position: relative;
          cursor: pointer;
          > div {
            width: 54%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            border-radius: 13px;
            background: linear-gradient(
              360deg,
              rgba(20, 123, 252, 1) 0%,
              rgba(12, 157, 254, 1) 40%,
              rgba(3, 191, 255, 1) 100%
            );
            z-index: 9;
          }
          .slide {
            transition: all 0.5s;
            width: 100%;
          }
          .close-slide {
            transition: all 0.5s;
            width: 54%;
          }
          i {
            position: absolute;
            right: 10px;
            top: 3px;
            font-size: 18px;
            color: red;
          }
        }
      }
    }
  }
}
</style>
<style lang="scss">
.right-home {
}
</style>
